home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000095_icon-group-sender _Fri Apr 22 09:58:30 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 22 Apr 1994 12:35:30 MST
  2. From: Nevin Liber <nevin@caslon>
  3. Message-Id: <199404221658.JAA20218@caslon.CS.Arizona.EDU>
  4. Subject: Re: is this a bug?
  5. To: icon-group@cs.arizona.edu (Icon Group)
  6. Date: Fri, 22 Apr 1994 09:58:30 -0700 (MST)
  7. Cc: janpeter@mpi.nl (Jan Peter de Ruiter)
  8. In-Reply-To: <9404221206.AA25564@mpix10.mpi.kun.nl> from "Jan Peter de Ruiter" at Apr 22, 94 01:06:56 pm
  9. X-Mailer: ELM [version 2.4 PL23]
  10. Content-Type: text
  11. Content-Length: 2482      
  12. Status: R
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14.  
  15. Jan Peter de Ruiter proudly drove the following message along the Information SuperHypeway(TM) at breakneck speeds:
  16.  
  17. > procedure main()
  18. >     t := table([]) # a table with default element []
  19. >     every put(t[1],generate(1,5)) # fill t[1], which is empty list
  20. >     every put(t[2],generate(6,9)) # fill t[2], which is empty list
  21. >     every(write(!t[1])) # write out all elements of t[1]
  22. >     write()
  23. >     every(write(!t[2])) # write out all elements of t[2]
  24. >     write(ximage(t)) # write out image of t 
  25. > end
  26. > procedure generate(a,b)
  27. >     every suspend (a to b)
  28. > end
  29.  
  30. >{Expectation:  t[1] <- [1,2,3,4,5], t[2] <- [6,7,8,9]}
  31. >{Result: (t[1] === t[2]) <- [1,2,3,4,5,6,7,8,9]]}
  32.  
  33. > Now my question is: have I understood the icon
  34. > semantics wrongly, or is this a bug?
  35.  
  36. It is part of the semantics, and not a bug.
  37.  
  38. >If anyone
  39. > understands what is happening here, could (s)he
  40. > please explain?
  41.  
  42. Let xDefault = the default value of the table (in this case, []).
  43.  
  44. You were expecting copy(xDefault) to be returned; however, xDefault is
  45. returned instead.  For structure types (lists, records, sets and
  46. tables), operations on expressions that have the same value as
  47. xDefault do their work on the same structure.  In other words, the
  48. compare values operator (===) will always be true when getting the
  49. xDefault element out of the table.
  50.  
  51. In your case, you never assign anything to the table, so t[1] and t[2]
  52. always return the same default list.
  53.  
  54.  
  55. BTW, even if tables had copy semantics for the xDefault element, the
  56. above program still wouldn't work.  Since nothing is ever assigned to
  57. the table, t[1] and t[2] would always return a copy of an empty list,
  58. and the observable result of the above code would be:
  59.  
  60.     ((t[1] <- []) ~=== (t[2] <- []))
  61.  
  62. [Actually, t[1] and t[2] are never defined; the above is if you did an
  63. assignment like
  64.  
  65.     t1 := t[1]
  66.     t2 := t[2]
  67.  
  68. and looked at t1 and t2.]
  69.  
  70.  
  71. Just wondering:  can anyone think of a situation where copy semantics
  72. would be desirable?
  73.  
  74.  
  75. What you really were expecting is the first time you referenced an
  76. element in a table, copy(xDefault) is assigned to that element.
  77. However, I don't believe that the benefits of this outweigh the
  78. consequences of having these semantics (eg: describing how tables work
  79. and what is and isn't a key of that table would be a nightmare to try
  80. and describe).
  81. -- 
  82.     Nevin ":-)" Liber    nevin@cs.arizona.edu    (602) 293-2799
  83.                                                   +++ (520) after 3/95
  84.                                       office:    (602) 621-1685
  85.